package com.c.ctgproject.adapter.review

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.cardview.widget.CardView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.entity.review.PartReviewEntity
import com.c.ctgproject.mode.ReviewEnum
import com.c.ctgproject.utils.handlerNull
import org.jetbrains.anko.textColorResource

class ReviewPartsCommonAdapter(private val context: Context, private val mList: List<PartReviewEntity.DataBean.ListBean>, private val result: PartsLiteItemClick) : RecyclerView.Adapter<ReviewPartsCommonAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_review_part_common_list, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int {
        return mList.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        val data = mList[position]
        holder.mOrderId.text=data.partsSalesNo.handlerNull()
        holder.mTimeTV.text=data.createTime.handlerNull()
        holder.mSellerTV.text=data.userName.handlerNull()
        when (data.isPass) {
            ReviewEnum.UN_REVIEWED.code -> {
                holder.mStatusTV.text = ReviewEnum.UN_REVIEWED.statueName
                holder.mStatusTV.textColorResource = ReviewEnum.UN_REVIEWED.color

            }
            ReviewEnum.AGREE.code -> {
                holder.mStatusTV.text = ReviewEnum.AGREE.statueName
                holder.mStatusTV.textColorResource = ReviewEnum.AGREE.color

            }
            ReviewEnum.REFUSE.code -> {
                holder.mStatusTV.text = ReviewEnum.REFUSE.statueName
                holder.mStatusTV.textColorResource = ReviewEnum.REFUSE.color
            }
        }
        holder.mCardView.setOnClickListener {
            result.itemClick(data)
        }

    }

    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val mOrderId: TextView = itemView.findViewById(R.id.mOrderIdTV)
        val mTimeTV: TextView = itemView.findViewById(R.id.mTimeTV)
        val mSellerTV: TextView = itemView.findViewById(R.id.mSellerTV)
        val mStatusTV: TextView = itemView.findViewById(R.id.mStatusTV)
        val mCardView: CardView = itemView.findViewById(R.id.mCardView)
    }


    interface PartsLiteItemClick {
        fun itemClick(data: PartReviewEntity.DataBean.ListBean)
    }
}